package com.kfm.am.conversion;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

public class InputStreamReaderDemo {

    public static void main(String[] args) {
        // 绝对路径 盘符开始
        // 相对路径：
        // 字符流  字节流转换成字符流
        // FileReader 从文件中获取字符流
        try(InputStreamReader inputStreamReader =
                    new InputStreamReader(new FileInputStream("io/in.txt"));
            InputStreamReader inputStreamReader1 =
                    new InputStreamReader(new FileInputStream("io/csb_gbk.txt"), "GBK");
            InputStreamReader inputStreamReader2 =
                    new InputStreamReader(new FileInputStream("io/in.txt"), Charset.forName("GBK"));) {
            System.out.println(inputStreamReader.getEncoding()); // UTF8
            System.out.println((char) inputStreamReader.read());
            System.out.println((char)inputStreamReader1.read());
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}
